Developer --> Technical Publications

     


Managing Windows In Response to the Display Notice Event

Using the Monitors control panel, the user can switch displays to use a different display mode and to change the display configurations. When your application receives the Display Notice event as described in the previous section, your application must determine whether it needs to reposition and perhaps resize its windows.

Listing 3-3 illustrates how an application can check whether its nonstandard window appears onscreen after Display Manager configuration changes have occurred. In this example, the application has a window with a title bar on its left side, as shown in the tool palette illustrated in Figure 2-4. After receiving the Display Notice event as shown in Listing 3-2, the application calls its MyDisplayWindows function, which in turn calls its MyMakeToolWindowVisible function. If MyMakeToolWindowVisible determines that the nonstandard title bar does not appear on any displays (in which case the user cannot move the window), MyMakeToolWindowVisible moves the entire window to the main screen where the user has access to the window.

Listing 3-3 Ensuring that a nonstandard window appears onscreen

static pascal OSErr MyMakeToolWindowVisible (WindowPeek window) {
    if (window->windowKind == applicationFloatKind) {
        Rect        checkRect;
        Rect        mainRect;
        GDHandle    maxAreaDevice;
        short       theWVariant;
        Rect        windowRect;
        theWVariant = GetWVariant(&window->port);
        MyGetWindowGlobalRect(window, &windowRect);                                                                                         
        /*get rectangle of window, in global coordinates, here */
        if (0 != (kVerBarFW & theWVariant)) 
        /* check if this is the window with a vertical title bar */
        {
        /* following line gets the rectangle of the title bar */
        SetRect(&checkRect, windowRect.left-kMyVertTitleWidth+kMyMinVisX,
                                     windowRect.top+kkMyMinVisV,
                                     windowRect.left-1-kMyMinVisX,
                                     windowRect.bottom-kMyMinVisV);
        /* following line calls an application-defined function that
        determines which screen contains the largest amount of the title 
        bar */
        maxAreaDevice = MyFindMaxCoverageDevice(&checkRect);
        if (nil == maxAreaDevice)
        /* if the title bar doesn't appear on any screen, move window to 
        the main screen */
        {   mainRect = (*GetMainDevice()) -> gdRect;
            MoveWindow(&Window->port, mainRect.left+10+kMyVertTitleWidth,
            mainRect.bottom-10-(windowRect.bottom-windowRec.top, FALSE);
        } }
        MyKeepWindowOnscreen(window, nil);
        /* handle other nonstandard window variants here */
        }
        return noErr;
}

Your application may find it useful to resize a window after moving it, or to optimize the color for its newly configured video device. You can use Display Manager functions to determine the characteristics of video devices, as explained in the next section.


© 2000 Apple Computer, Inc. (Last Updated 07 April 00)